package com.zhentao.day01.am;

public class Person  {

  private String name ;
  private int age ;


  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public int getAge() {
    return age;
  }

  // 声明的异常类, 在赋值的方法上, 声明 抛出异常 , throws 代表抛出给其余的方法来解决相关的异常
  public void setAge(int age) throws RuntimeException {
    if (age < 0 ){
      throw  new AgeException("年龄小");
    }
    if (age > 120){
      throw new AgeException("年龄大");
    }
    this.age = age;
  }
}
